# 图像梯度运算(膨胀 — 腐蚀)

import cv2
import numpy as np

# 读取图片
src = cv2.imread('src/img.png', cv2.IMREAD_UNCHANGED)

# 设置卷积核
kernel = np.ones((3, 3), np.uint8)

# 图像闭运算
result = cv2.morphologyEx(src, cv2.MORPH_GRADIENT, kernel)

# 显示图像
cv2.imshow("src", src)
cv2.imshow("result", result)

# 等待显示
cv2.waitKey(0)
cv2.destroyAllWindows()